// 设备API的混合数据版本
import { hybridRequest } from './hybridApi';

// 获取所有设备列表
export const getAllDevices = (params) => {
  return hybridRequest('/device/list', { method: 'GET', params });
};

// 获取单个设备详情
export const getDeviceById = (id) => {
  return hybridRequest(`/device/${id}`, { method: 'GET' });
};

// 添加新设备
export const addDevice = (data) => {
  return hybridRequest('/device', { method: 'POST', data });
};

// 更新设备信息
export const updateDevice = (id, data) => {
  return hybridRequest(`/device/${id}`, { method: 'PATCH', data });
};

// 删除设备
export const deleteDevice = (id) => {
  return hybridRequest(`/device/${id}`, { method: 'DELETE' });
};

// 获取设备的空气质量数据
export const getDeviceAirData = (deviceId) => {
  return hybridRequest('/data/today', { method: 'GET', params: { deviceId } });
};

// 获取设备详细数据，包括状态、电量等
export const getDeviceData = (params) => {
  return hybridRequest('/device/status', { method: 'GET', params });
};

// 获取设备使用统计数据
export const getDeviceUsageStats = (deviceId, dateRange, granularity) => {
  return hybridRequest('/device/usage', { 
    method: 'GET',
    params: { 
      deviceId, 
      startDate: dateRange[0], 
      endDate: dateRange[1], 
      granularity 
    } 
  });
};

// 获取设备异常数据
export const getDeviceAbnormalData = (deviceId, period) => {
  return hybridRequest('/device/abnormal', { 
    method: 'GET', 
    params: { deviceId, period } 
  });
};

// 绑定设备
export const bindDevice = (data) => {
  return hybridRequest('/device/bind', { method: 'POST', data });
};

// 解绑设备
export const unbindDevice = (data) => {
  return hybridRequest('/device/unbind', { method: 'POST', data });
};
